﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

public partial class AdminX_Hotel_BookingHotelAdd : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MessAlert1.HideMessage();
        if (!IsPostBack)
        {
            SetLabelLanguage();
            BindDataWhenEdit();
        }
    }
    private void SetLabelLanguage()
    {
        int nDefaultLanguage = Support.GetDefaultLanguage();
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nDefaultLanguage - 1];
        lblContactPhone.Text = MultipleLanguage.TELEPHONE[nDefaultLanguage - 1];
        lblContactEmail.Text = MultipleLanguage.EMAIL[nDefaultLanguage - 1];
        lblContactFullname.Text = MultipleLanguage.FULLNAME[nDefaultLanguage - 1];
        lblExtraBed.Text = MultipleLanguage.LBL_EXTRABED[nDefaultLanguage - 1];
        lblFinishDate.Text = MultipleLanguage.LBL_FINISHDATE[nDefaultLanguage - 1];
        lblOtherRequest.Text = MultipleLanguage.LBL_OTHERREQUEST[nDefaultLanguage - 1];
        lblPayment.Text = MultipleLanguage.LBL_PAYMENT[nDefaultLanguage - 1];
        lblRoomType.Text = MultipleLanguage.LBL_ROOMTYPE[nDefaultLanguage - 1];
        //lblStarRating.Text = MultipleLanguage.STARRATING[nDefaultLanguage - 1];
        lblStartDate.Text = MultipleLanguage.LBL_STARTDATEBOOKING[nDefaultLanguage - 1];
        lblHotel.Text = MultipleLanguage.HOTEL[nDefaultLanguage - 1];
        lblCountry.Text = MultipleLanguage.LBL_COUNTRY[nDefaultLanguage - 1];
        btnBack.Text = MultipleLanguage.BTN_BACK[nDefaultLanguage - 1];

    }
    #region Relative Functions
    private void BindDataWhenEdit()
    {
        string sAction = ConvertData.ConvertToString(Request.QueryString[Config.ACTION]);
        try
        {
            if (sAction == Config.ACTION_EDIT)
            {
                int nID = ConvertData.ConvertToInt(Request.QueryString[Config.ACTION_ID]);
                if (nID > 0)
                    GetData(nID);
            }
        }
        catch
        {
            string sLink = Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_BOOKINGHOTEL;
            Response.Redirect(sLink);
        }
    }
    private void GetData(int nID)
    {
        HotelBooking objHotelBooking = new HotelBooking();
        objHotelBooking.LoadById(nID);

        Hotel objBooking = new Hotel();
        objBooking.LoadById(objHotelBooking.Data.HotelBookingID);
        int nDefaultLanguage = Support.GetDefaultLanguage();
        switch (nDefaultLanguage)
        { 
            case 1:
                lblValHotel.Text = ConvertData.ConvertToString(objBooking.Data.Title1);
                break;

            case 2:
                lblValHotel.Text = ConvertData.ConvertToString(objBooking.Data.Title2);
                break;

            case 3:
                lblValHotel.Text = ConvertData.ConvertToString(objBooking.Data.Title3);
                break;
        }
        lblValContactEmail.Text = ConvertData.ConvertToString(objHotelBooking.Data.Email);
        lblValContactFullname.Text = ConvertData.ConvertToString(objHotelBooking.Data.FullName);
        if (objHotelBooking.Data.NumberOfExtraBed > 0)
        {
            lblValExtraBed.Text = "Yes";
        }
        else
        {
            lblValExtraBed.Text = "No";
        }
        lblValContactPhone.Text = ConvertData.ConvertToString(objHotelBooking.Data.Phone);
        lblValFinishDate.Text = ConvertData.ConvertToString(objHotelBooking.Data.CheckOut);
        lblValOtherRequest.Text = ConvertData.ConvertToString(objHotelBooking.Data.QuestionsAndComments);
        lblValStartDate.Text = ConvertData.ConvertToString(objHotelBooking.Data.CheckIn);
        //lblValStarRating.Text = ConvertData.ConvertToString(objHotelBooking.Data.HotelBookingID);
        Payment objPayment = new Payment();
        objPayment.LoadById(objHotelBooking.Data.PaymentID);
        lblValPayment.Text = ConvertData.ConvertToString(objPayment.Data.Description);
        RoomType objRoomType = new RoomType();
        objRoomType.LoadById(objHotelBooking.Data.RoomClass);
        lblValRoomType.Text = ConvertData.ConvertToString(objHotelBooking.Data.RoomClass);

        switch (nDefaultLanguage)
        { 
            case 1:
                lblValRoomType.Text = ConvertData.ConvertToString(objRoomType.Data.Description1);
                break;

            case 2:
                lblValRoomType.Text = ConvertData.ConvertToString(objRoomType.Data.Description2);
                break;

            case 3:
                lblValRoomType.Text = ConvertData.ConvertToString(objRoomType.Data.Description3);
                break;
        }

        Hotel objHotel = new Hotel();
        objHotel.LoadById(objHotelBooking.Data.HotelID);
        lblValHotel.Text = ConvertData.ConvertToString(objHotel.Data.HotelID);
        switch (nDefaultLanguage)
        {
            case 1:
                lblValHotel.Text = ConvertData.ConvertToString(objHotel.Data.Title1);
                break;

            case 2:
                lblValHotel.Text = ConvertData.ConvertToString(objHotel.Data.Title2);
                break;

            case 3:
                lblValHotel.Text = ConvertData.ConvertToString(objHotel.Data.Title3);
                break;
        }

        Country objCountry = new Country();
        objCountry.LoadById(objHotelBooking.Data.CountryID);
        lblValCountry.Text = ConvertData.ConvertToString(objCountry.Data.CountryID);
        switch (nDefaultLanguage)
        { 
            case 1:
                lblValCountry.Text = ConvertData.ConvertToString(objCountry.Data.CountryName1);
                break;

            case 2:
                lblValCountry.Text = ConvertData.ConvertToString(objCountry.Data.CountryName2);
                break;

            case 3:
                lblValCountry.Text = ConvertData.ConvertToString(objCountry.Data.CountryName3);
                break;
        }
        int nResult = objHotelBooking.UpdateStatus(nID, EnumeType.ACTIVE);
    }
    #endregion
#region Click Events
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect(Config.ROOT + Pages.BackEnds.ADMIN + "?" + Config.PAGE + "=" + Pages.BackEnds.STR_BOOKINGHOTEL);
    }
#endregion
}
